version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.XIII OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

/* PRELIMINARIES */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
keep			regno year name_count_v2 TaxPaid taxableinc
#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* DEFINE TREATMENT VARIABLE */

g				logtaxpaid=log(TaxPaid)
bys				regno:egen namefreq=min(name_count_v2)
g				after=year>=2012
g				treat=namefreq<=40
g				treat_after=treat*after
qui				count if taxableinc>0 & taxableinc<. & year==2011
local			universe=r(N)

/* COMPLETE PANEL */


local			i=1
local			j=1
foreach 		u in 100000 200000 300000 400000 500000 600000{
local			l=`u'-100000
cap				drop group*
g				group_t=taxableinc>`l' & taxableinc<=`u' & year==2011
bys				regno:egen group=max(group_t)
qui				areg logtaxpaid i.year treat_after if group==1, absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
qui				count if taxableinc>0 & taxableinc<`u' & year==2011
matrix			table[`i'+3,`j']=(r(N)/`universe')*100
local			j=`j'+1
}

*--------------------------------
* PLACEBO REGRESSION 
*--------------------------------

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
keep			regno year name_count_v2 TaxPaid taxableinc
g				logtaxpaid=log(TaxPaid)
bys				regno:egen namefreq=min(name_count_v2)
keep			if year<=2011
g				after=year>=2010
g				treat=namefreq<=40
g				treat_after=treat*after
qui				count if taxableinc>0 & taxableinc<. & year==2009
local			universe=r(N)

/* COMPLETE PANEL */


local			i=5
local			j=1
foreach 		u in 100000 200000 300000 400000 500000 600000 {
local			l=`u'-100000
cap				drop group*
g				group_t=taxableinc>`l' & taxableinc<=`u' & year==2009
bys				regno:egen group=max(group_t)
qui				areg logtaxpaid i.year treat_after if group==1, absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
qui				count if taxableinc>0 & taxableinc<`u' & year==2009
matrix			table[`i'+3,`j']=(r(N)/`universe')*100
local			j=`j'+1
}




/* FORMATTING THE TABLE */ 

svmat 			table
keep			tab*
drop			table7-table12
keep			if _n<=7
drop			if _n==4			//percentiles: column(1) 2.9 column(2) 19.09 column(3) 60.27 column (4) 92.56 column (5) 95.7 column (6) 96.54
g				c11=""
replace			c11="treat $\times$ after" in 1
replace			c11="Observations" in 3
replace			c11="treat $\times$ after" in 4
replace			c11="Observations" in 6

forvalues 		c=1/6 {
g				c`c'=string(table`c',"%9.3f")
}
foreach			r in 2 5 {
forvalues		c=1/6 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/6 {
replace			c`c'=string(table`c',"%15.0fc") in 3
replace			c`c'=string(table`c',"%15.0fc") in 6
}
forvalues		s=1/15 {
g				s`s'="&"
}
g				l="\\"
foreach			r in 2 3 5 6 {
replace			l="\\\\" in `r'
}
order			c11 s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 l
browse			c11 s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 l


